<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<script src="${ctx}/style/js/jquery.js"></script>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
	
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>错题上传</li>
			</ul>
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
							
			</div> 
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" onsubmit="return uploadQuestions();" role="form" id="uploadForm" name="uploadForm" method="post">
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">错题标题</label>
							<div class="col-sm-9">
								<input type="text" id="title"  name="title" value="" placeholder="错题标题" class="col-xs-10 col-sm-5" size="50" />
							</div>
						</div>
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">科目</label>
							<div class="col-sm-9">
							<select id="subjectId" name="subjectId">
							<option value="1">语文</option>
							<option value="2">数学</option>
							<option value="3">英语</option>
							</select>
							</div>
						</div>
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">文件</label>
							<div class="col-sm-9">
								<input type="file" id="img"  name="img" accept="image/gif,image/png,image/jpeg" placeholder="请选择数据文件" onchange="setValue(this.value)" class="col-xs-10 col-sm-5"  />
							</div>
							<div class="error" style="margin:6px 0 0 112px;display: block;"></div>
						</div>
						<input type="hidden" id="openId"  name="openId" value="1234567"/>
						
						<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button class="btn btn-info" type="submit">
									<i class="icon-ok bigger-110"></i>提交
								</button>
							</div>
						</div>
						
					</form>		
				</div>
							
			</div>
		</div>
		
		<script type="text/javascript">
			function uploadImg() {
				var file=$("#img");
	            if($.trim(file.val())==''){
	            	$(".error").html("* 请选择图片");
	                   return false;
	             }
			    var formData = new FormData($("#uploadForm")[0]);
			    formData.openId = $("#openId").val();
				var datastr = new Object();
	    		datastr.openId = $('#openId').val();
				var result = true;
					$.ajax({
					url: "${ctx}/api/user/imgUpload",
					type: "POST",
			        data: formData,
			        async: false,
			        cache: false,
			        contentType: false,
			        processData: false,
	                success : function(data) {
	                	var dataobj = JSON.parse(data);
	                	if (dataobj != undefined && dataobj.status != undefined
	                			&& dataobj.status.trim() == '0') {
	                		result = true;
	                		alert("保存成功！文件为"+dataobj.data.fileName  +"路径为"+dataobj.data.filePath);
// 	                		window.location.href = "";
	                	} else {
	                		result = false;
	                		alert(dataobj.message);
	                	}
	                },
	    		},"json");
				return false;
			}
			
			function uploadQuestions() {
				var subjectId = $("#subjectId").val();
				alert(subjectId);
				var file=$("#img");
	            if($.trim(file.val())==''){
	            	$(".error").html("* 请选择图片");
	                   return false;
	             }
			    var formData = new FormData($("#uploadForm")[0]);
			    formData.openId = $("#openId").val();
			    formData.title = $("#title").val();
			    formData.subjectId = $("#subjectId").val();
				var result = true;
					$.ajax({
					url: "${ctx}/api/user/uploadQuestions",
					type: "POST",
			        data: formData,
			        async: false,
			        cache: false,
			        contentType: false,
			        processData: false,
	                success : function(data) {
	                	var dataobj = JSON.parse(data);
	                	if (dataobj != undefined && dataobj.status != undefined
	                			&& dataobj.status.trim() == '0') {
	                		result = true;
	                		alert("保存成功");
// 	                		window.location.href = "";
	                	} else {
	                		result = false;
	                		alert(dataobj.message);
	                	}
	                },
	    		},"json");
				return false;
			}
			
			 $(function(){
				
			 });
		</script>
	</body>


</html>